﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package com.fminutes.vinciIsometric.core {
    import com.fminutes.vinciIsometric.core.IsoConst.*;

    public class IsoMapItem {

        private var _x:int = 0;
        private var _z:int = 0;
        private var _floorList:Array;
        private var _stationaryList:Array;

        public function IsoMapItem(_arg1:int, _arg2:int){
            this._x = _arg1;
            this._z = _arg2;
        }
        public function get floorList():Array{
            return (this._floorList);
        }
        public function get stationaryList():Array{
            return (this._stationaryList);
        }
        public function get isoList():Array{
            var _local1:Array = (((!((this.stationaryList == null))) && ((this.stationaryList.length > 0)))) ? this.stationaryList : [];
            var _local2:Array = (((!((this.floorList == null))) && ((this.floorList.length > 0)))) ? this.floorList : [];
            return (_local1.concat(_local2));
        }
        public function addIso(_arg1:IsoObject):void{
            if (_arg1.type == IsoType.FLOOR){
                if (this._floorList == null){
                    this._floorList = [];
                };
                this._floorList.push(_arg1);
            } else {
                if (_arg1.type == IsoType.STATIONARY){
                    if (this._stationaryList == null){
                        this._stationaryList = [];
                    };
                    this._stationaryList.push(_arg1);
                };
            };
        }
        public function removeIso(_arg1:IsoObject):void{
            var _local2:int;
            if (_arg1.type == IsoType.FLOOR){
                if (this._floorList == null){
                    return;
                };
                _local2 = 0;
                while (_local2 < this._floorList.length) {
                    if (this._floorList[_local2] == _arg1){
                        this._floorList.splice(_local2, 1);
                        return;
                    };
                    _local2++;
                };
            } else {
                if (_arg1.type == IsoType.STATIONARY){
                    if (this._stationaryList == null){
                        return;
                    };
                    _local2 = 0;
                    while (_local2 < this._stationaryList.length) {
                        if (this._stationaryList[_local2] == _arg1){
                            this._stationaryList.splice(_local2, 1);
                            return;
                        };
                        _local2++;
                    };
                };
            };
        }
        public function removeAll():void{
            this._floorList = null;
            this._stationaryList = null;
        }
        public function get walkable():int{
            var _local3:IsoObject;
            var _local4:IsoPosition;
            var _local5:int;
            var _local6:int;
            var _local7:int;
            var _local1 = 1;
            var _local2:int;
            while (_local2 < this.isoList.length) {
                _local3 = (this.isoList[_local2] as IsoObject);
                if ((((_local3.walkable == 0)) && (!((_local3.type == IsoType.MOVING))))){
                    if (_local3.barrier == null){
                        return (0);
                    };
                    _local4 = _local3.isoPosition;
                    _local5 = (this._x - _local4.x);
                    _local6 = (this._z - _local4.z);
                    _local7 = _local3.barrier[_local5][_local6];
                    if ((((_local1 < _local7)) && (!((_local7 == 0))))){
                        _local1 = _local7;
                    } else {
                        if (_local7 == 0){
                            return (0);
                        };
                    };
                } else {
                    if (((!((_local3.walkable == 0))) && (!((_local3.type == IsoType.MOVING))))){
                        if (_local3.walkable > _local1){
                            _local1 = _local3.walkable;
                        };
                    };
                };
                _local2++;
            };
            return (_local1);
        }
        public function get baseIsoObject():IsoObject{
            if ((((this.stationaryList == null)) || ((this.stationaryList.length == 0)))){
                return (null);
            };
            var _local1:IsoObject = this.stationaryList[0];
            var _local2 = 1;
            while (_local2 < this.stationaryList.length) {
                if (this.stationaryList[_local2].y > _local1.y){
                    _local1 = this.stationaryList[_local2];
                };
                _local2++;
            };
            return (_local1);
        }
        public function getTopIsoObject(_arg1:Boolean):IsoObject{
            var _local2:IsoObject;
            var _local3:int;
            if ((((this.stationaryList == null)) || ((this.stationaryList.length == 0)))){
            } else {
                _local2 = this.stationaryList[0];
                _local3 = 1;
                while (_local3 < this.stationaryList.length) {
                    if (this.stationaryList[_local3].y < _local2.y){
                        if ((((_arg1 == true)) || (((this.stationaryList[_local3] as IsoObject).wallpaper == false)))){
                            _local2 = this.stationaryList[_local3];
                        };
                    };
                    _local3++;
                };
                if ((((_arg1 == true)) || ((_local2.wallpaper == false)))){
                    return (_local2);
                };
            };
            if ((((this.floorList == null)) || ((this.floorList.length == 0)))){
                return (null);
            };
            _local3 = 0;
            while (_local3 < this.floorList.length) {
                if ((this.floorList[_local3] as IsoObject).isContainer == false){
                    return (this.floorList[_local3]);
                };
                _local3++;
            };
            return (null);
        }
        public function get topIsoObject():IsoObject{
            return (this.getTopIsoObject(true));
        }

    }
}//package com.fminutes.vinciIsometric.core 
